
/**
 * 
 * @param {import ("./Plot").Plot }   plot 
 */

function initMathDraw(plot) {
    var MathDraw = {
        sin: function (angle) {
            for (var i = 0; i < angle; i++) {
                plot.drawDot({x: i, y: Math.sin(i / 180 * Math.PI) * 100});
            }
        },
        //tan函数曲线
        tan: function () {
            for (var i = 0; i < 720; i++) {
                if (Math.tan(i / 180 * Math.PI) * 100 > plot.origin.y) {
                    continue;
                }
                plot.drawDot({x: i, y: Math.tan(i / 180 * Math.PI) * 50});
            }
        },
        //cos函数曲线，传入角度，比如90，180，360
        cos: function (angle) {
            for (var i = 0; i < angle; i++) {
                plot.drawDot({x: i, y: Math.cos(i / 180 * Math.PI) * 100});
            }
        },
        //画多边形，传入一个点列
        polygon: function (dots) {
            if (typeof dots == 'undefined') {
                alert('you should specify some dots to draw!');
                return;
            }
            if (dots.constructor != Array) {
                alert('you should specify some dots to draw!');
                return;
            }
            for (var i = 0; i < dots.length - 1; i++) {
                plot.line(dots[i].x, dots[i].y, dots[i + 1].x, dots[i + 1].y);
                if (i == 1 && dots.length == 2) {
                    break;
                }
            }
            plot.line(dots[0].x, dots[0].y, dots[dots.length - 1].x, dots[dots.length - 1].y);
        }
    
    };
}

